package band.wukong.practice.javase.core.thread.sync;

import java.io.IOException;

/**
 * Desc: 线程没有做同步。书上本来有a只鸟，飞来i只，又飞走i只……
 * Author: sunjs
 * Date: 2009-11-5 16:24:41
 */
public class TestUnSync implements Runnable {
    private int a = 1;

    public void run() {
        for (int i = 0; i < 10; i++) {
            a += i;
            Thread.yield();
            a -= i;
            System.out.println(Thread.currentThread().getName() + ":" + "a=" + a);
        }
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        TestUnSync m = new TestUnSync();
        Thread t1 = new Thread(m);
        Thread t2 = new Thread(m);

        t1.setName("T1");
        t2.setName("T2");

        t1.start();
        t2.start();

    }
}
